package com.chexiehui.jc.mvp.car;

import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.BrandSeriesInfo;

/**
 * @Description 品牌车系列表
 * @Auth SongJun
 * @Date 2020/05/21 00:18
 **/
public class CarBrandSaleListPresenter extends BasePresenter<CarBrandSaleListCovenant.View, CarBrandSaleListCovenant.Stores>
        implements CarBrandSaleListCovenant.Presenter {

    public CarBrandSaleListPresenter(CarBrandSaleListCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getBrandSeriesInfo() {
        addSubscription(appStores.getBrandSeriesInfo(mvpView.getBrandId(), mvpView.getCarType(), mvpView.getEnergy()),
                new ApiCallback<BaseModel<BrandSeriesInfo>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<BrandSeriesInfo> model) {
                        if (model.getResultCode() == 0) {
                            if (model.getData() != null) {
                                mvpView.onGetBrandSeriesInfoSuccess(model);
                            } else {
                                onFailure(Constants.PAGE_DATA_EMPTY, "暂无车系信息");
                            }
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGetBrandSeriesInfoFailure(new BaseModel<>(code, msg));
                    }
                });
    }

}